import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:huajianshe_app/base/AppNavigator.dart';
import 'package:huajianshe_app/base/BaseState.dart';
import 'package:huajianshe_app/common/load_image.dart';
import 'package:huajianshe_app/common/res.dart';
import 'package:huajianshe_app/utils/toast_utils.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';
import 'package:huajianshe_app/widget/SmartButton.dart';

class ImportFriendsDialog extends StatefulWidget {

  final String? importUrl;

  const ImportFriendsDialog(this.importUrl, {Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _ImportFriendsDialogState();
  }
}

class _ImportFriendsDialogState extends BaseState<ImportFriendsDialog> {
  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(0),
      ),
      elevation: 0,
      backgroundColor: Colors.transparent,
      child: buildChild(context),
    );
  }

  Widget buildChild(BuildContext context) {
    return
      Column(mainAxisSize: MainAxisSize.min, children: [
        RoundedCornerWidget(borderWidth: 0, radius: 13,
            gradient: LinearGradient(colors: [Color(0xFFFFEBED), Color(0xFFFFFFFF)],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter),
            child: Column(mainAxisSize: MainAxisSize.min, children: [
              H(38),
              Text('请使用浏览器打开如下网址', style: TS(17, C.gray333, fontWeight: FontWeight.bold)),
              H(10),
              Padding(padding: EdgeInsets.symmetric(horizontal: 13), child: Text('${widget.importUrl}', style: TS(15, C.gray666))),

              H(25),
              Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
                SmartButton(width: 265, height: 40, radius: 20, text: '复制网址', fontSize: 15, textColor: Colors.white,
                  onPressed: copy,),

              ],),
              H(23)
            ])
        ),
        H(14),
        InkWell(onTap: () => AppNavigator.pop(context), child: LoadImage('close_27'),)
      ],);

  }

  copy() {
    Clipboard.setData(ClipboardData(text: widget.importUrl)).then((value) => {
      Toast.show('已复制${widget.importUrl}'),
      AppNavigator.pop(context)
    });
  }
}